import java.util.Scanner;

public class Main1 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 0, j = 1;
        int a = 0;
        while (a < n) {
            a = i + j;
            i = j;
            j = a;
        }
        int left = n - i;
        int right = a - n;
        int answer = Math.min(left, right);
        System.out.println(answer);
    }
}
